<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Repositories\ReplyRepository;

class ReplyController extends AdminController
{
    public function __construct(ReplyRepository $reply)
    {
        $this->reply = $reply;
    }

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        $data = $this->reply->paginateList();
        return view('admin.reply.index', compact('data'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  Request  $request
     * @return Response
     */
    public function store(Request $request)
    {
        $data = [
            'order_id' => $request->input('order_id'),
            'user_id'  => auth()->user()->id,
            'content'  => $request->input('content')
        ];

        $result = $this->reply->create($data);

        if ($result) {
            return back()->with('success', '发表回复成功');
        }

        return back()->with('error', '发表回复失败');
    }
}
